// #include <string>
// #include <vector>
// #include <stdio.h>
// #include <iostream>
// #include "JsonSerializer.h"
// #include "JsonDeserializer.h"
// #include ""

#include "includes.h"


class  animal
{
	public:
	std::string type;
	_CLASSS_JSON_DEFAULT(type);
};


class Person
{
public:
	int							age;
	std::string					name;
	std::vector<std::string>	skills;
	animal                      an;
	_CLASSS_JSON_DEFAULT(age,name,skills,an);
};
class Club 
{
public:
    int                         id;
	std::string					name;
	std::string					location;
	std::vector<Person>			memberInfo;
	long                        scope;
    
	_CLASSS_JSON_DEFAULT(id,name,location,memberInfo,scope);
};

static std::string GetJsonString()
{
	return "{ \"scope\":99,  \"id\":123,\"name\": \"Tennis Club   \",\"location\" : \"xxx, Hedong District, Tianjin, China.\",\"memberInfo\" : [{\"name\": \"zcc\",\"age\" : 23,\"skills\" : [\"writing\",\"photography\",\"programming\"]},{\"name\": \"xyx\",\"age\" : 22,\"skills\" : [\"playing the piano\",\"dancing\"]}]}";
}
static void PrintClubObject(const Club& club)
{
	std::cout << "====================print club object start====================" << std::endl;

    std::cout << "id: " << club.id << std::endl;
	std::cout << "name: " << club.name << std::endl;
	std::cout << "location: " << club.location << std::endl;
	std::cout << "memberInfo: " << std::endl;
	for (const auto& member : club.memberInfo)
	{
		std::cout << "\tname: " << member.name << std::endl;
		std::cout << "\tage " << member.age << std::endl;
		std::cout << "\tskills: " << std::endl;
		for (const auto& skill : member.skills)
		{
			std::cout << "\t\t" << skill << std::endl;
		}
	}
	std::cout << "====================print club object end ======================" << std::endl;
}
static void PrintJsonString(const std::string& json)
{
	std::cout << "====================print json string start ====================" << std::endl;
	std::cout << json << std::endl;
	std::cout << "====================print json string end  ======================" << std::endl;
}

void test_json_serialize()
{
	//创建反序列化对象
	JsonDeserializer jdl(GetJsonString());	//传入std::string类型,当作json string处理
	//JsonDeserializer jdl("club.txt");		//传入const char*类型，当作文件路径处理

	//执行反序列化
	Club club;
	jdl.Deserialize(club);

	//遍历输出Club对象
	PrintClubObject(club);

	// //任意修改对象属性，以location为例
	// club.location = "Beijing, China.....";

	//创建序列化对象
	JsonSerializer js;					//空参数构造函数,则序列化时只返回json字符串
	//JsonSerializer js("club.txt");	//构造函数传入文件路径,则序列化时还会输出到文件

	//执行序列化
	std::string serialString = js.Serialize(club);
	std::string filejson = js.Serialize(club,"club.json");

	Json::Value j;
	Json::string2json(&j,serialString.c_str());

	std::string jstr = Json::json2string(j,false);
	std::cout << jstr;

	//输出序列化结果
	PrintJsonString(serialString);

    std::stringstream ss;
	ss << club.name;
	std::cout << ss.str();



}